<?php // no direct access
defined('_JEXEC') or die('Restricted access');
$cparams =& JComponentHelper::getParams('com_media');

?>

<?php 
if ($this->params->get('show_page_title', 1)) : 
	// Catturo itemId
	global $Itemid;
	
	// Catturo itemMenu raggiunto
	$itemMenu = $mainframe -> getMenu() -> getItem($Itemid);
	
	// Caso borse di studio
	if(in_array(88, $itemMenu -> tree) || in_array(89, $itemMenu -> tree)) {
		
		// Root
		$rootMenu = $mainframe -> getMenu() -> getItem($itemMenu -> tree[0]); 
		
	?>
		<h2><?php echo $rootMenu -> name . " " . $itemMenu->name; ?></h2>
	
	<?php
	} else {
	?>
	
		<h2><?php echo $itemMenu->name; ?></h2>
	
	<?php
	}

endif; 
?>

	<jdoc:include type="modules" name="intro" />

<?php 
// Se devo mostrare articoli leading 
if ($this->params->get('num_leading_articles')) :

	// Ciclo su articoli leading 
	for ($i = $this->pagination->limitstart; $i < ($this->pagination->limitstart + $this->params->get('num_leading_articles')); $i++) : 
		
		// Check ultimo articolo
		$last = ($i+1 == ($this->pagination->limitstart + $this->params->get('num_leading_articles'))) || $i+1 == $this->total;
		
		// Se supero numero articoli disponibili
		if ($i >= $this->total) : 
			// Ciclo a vuoto
			break; 
		endif; 
		
		// Blocco 
		echo "<div class=\"item" . ($last ? " last" : "") . "\">";
		
		// Separatore
		echo "<div class=\"separatore\"></div>";
				
		// Mostro i-esimo elemento
		$this->item =& $this->getItem($i, $this->params);
		echo $this->loadTemplate('item');
		
		echo "</div>";

	endfor; 

else : 

	// Forzo indice a inizio paginazione
	$i = $this->pagination->limitstart; 

endif; 
?>

<?php
/*

<?php
// Blocco articoli intro
$startIntroArticles = $this->pagination->limitstart + $this->params->get('num_leading_articles');
$numIntroArticles = $startIntroArticles + $this->params->get('num_intro_articles');

// Se richiesti intro e c'� ancora spazio (paginazione) 
if (($numIntroArticles != $startIntroArticles) && ($i < $this->total)) : 
?>

	<div class="blog<?php echo $this->params->get('pageclass_sfx');?> intro">
	<?php
	$divider = '';
	
	// Ciclo su numero colonne
	for ($z = 0; $z < $this->params->get('num_columns'); $z ++) :
		if ($z > 0) : 
			$divider = " column_separator"; 
		endif; 
		?>
			<div class="article_column<?php echo $divider ?>">
			
			<?php 
			// Ciclo su intro per colonna 
			for ($y = 0; $y < ($this->params->get('num_intro_articles') / $this->params->get('num_columns')); $y ++) :
				
				// Se non ho superato il limite di articoli
				if ($i < $this->total && $i < ($numIntroArticles)) :
					
					// Mostro i-esimo articolo
					$this->item =& $this->getItem($i, $this->params);
					echo $this->loadTemplate('item');
					$i ++;
				
				endif;
			endfor; 
			?>
			</div>
	<?php 
	endfor; 
	?>
	</div>

<?php 
endif; 
?>

<?php 
// Links ulteriori
if ($this->params->get('num_links') && ($i < $this->total)) : 
?>
	<div class="blog_more<?php echo $this->params->get('pageclass_sfx') ?>">
		<?php
			$this->links = array_splice($this->items, $i - $this->pagination->limitstart);
			echo $this->loadTemplate('links');
		?>
	</div>
<?php 
endif; 
?>

*/
?>

<span class="pagination">
<?php 
// Paginazione 
if ($this->params->get('show_pagination')) : 
	echo $this->pagination->getPagesLinks();
endif; 
?>
</span>

<div class="pagecounter">
<?php 
// Totale paginato
if ($this->params->get('show_pagination_results')) : 
	echo $this->pagination->getPagesCounter();
endif; 
?>
</div>

<br/>